package com.ccit.common.utils;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.poi.ss.formula.functions.T;

import java.util.ArrayList;
import java.util.List;

public class PageUtil {

    public static Page getPages(Integer current, Integer size, List list){
        List pageList = new ArrayList<>();
        int curIdx = current > 1 ? (current - 1) * size : 0;
        for (int i = 0; i < size && curIdx + i < list.size(); i++) {
            pageList.add(list.get(curIdx + i));
        }
        Page page = new Page<>(current, size);
        page.setRecords(pageList);
        page.setTotal(list.size());
        return page;

     /*   Page<T> page = new Page<T>(current, size);

        if(size > list.size()) {
            size = list.size();
        }
        int startIndex = Math.toIntExact(Math.min((current - 1) * size, list.size()));

        int endIndex = Math.toIntExact(Math.min(startIndex + size, list.size()));

        List<T> records1 = list.subList(startIndex, endIndex);

        page.setTotal(list.size());

        page.setRecords(records1);

        return page;*/
    }

}
